﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace WindowsFormsAppDatabase
{
    //数据库文件
    internal class Dao
    {
        //连接对象
        SqlConnection sc;
        //创建连接对象
        public SqlConnection connect()
        {

            string str = "server=无敌暴龙战神;database=calendar;Max Pool Size=1000;integrated security=sspi";
            sc = new SqlConnection(str);
            //连接
            sc.Open();
            return sc;
        }
        //执行sql语句 sql语句作为参数传递
        public SqlCommand command(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, connect());
            return cmd;
        }
        //返回sql语句更新的行数 用于增改
        public int Execute(string sql)
        {
            return command(sql).ExecuteNonQuery();
        }
        //返回select语句查询到的内容
        public SqlDataReader read(string sql)
        {
            return command(sql).ExecuteReader();
        }
        public void close()
        {
            sc.Close();
        }
    }
}
